local skel = fk.CreateSkill {
  name = "lb__juefa",
}

local DIY = require "packages.diy_utility.diy_utility"

Fk:loadTranslationTable {
  ["lb__juefa"] = "绝罚",
  [":lb__juefa"] = "本回合弃牌堆中的花色被补齐时，你可视为使用一张改为冰冻伤害、伤害+1、无视防具的【万箭齐发】，然后摸两张牌并于本回合结束后获得一个额外的出牌阶段。",

  --["@[suits]lb__juefa"] = "绝罚",
  ["#lb__juefa"] = "绝罚：你可视为使用一张改为冰冻伤害、伤害+1、无视防具的【万箭齐发】，然后摸两张牌并于本回合结束后获得一个额外的出牌阶段",

  ["$lb__juefa1"] = "就由我亲手铸就，伟大的新世界！",
  ["$lb__juefa2"] = "力量会给予希望！",
}

skel:addEffect(fk.AfterCardsMove, {
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    if player:hasSkill(skel.name) and not room:getBanner("#CenterSuitComplete") then
      local suits = {}
      for _, id in ipairs(DIY.getCenterCards(room)) do
        local suit = Fk:getCardById(id).suit
        if suit ~= Card.NoSuit then
          table.insertIfNeed(suits, suit)
        end
      end
      return #suits == 4
    end
  end,
  on_cost = function(self, event, target, player, data)
    local use = player.room:askToUseVirtualCard(player, {
      name = "archery_attack",
      skill_name = skel.name,
      cancelable = true,
      prompt = "#lb__juefa",
      skip = true,
    })
    if use then
      event:setCostData(self, { use = use })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local use = event:getCostData(self).use ---@type UseCardDataSpec
    use.additionalDamage = (use.additionalDamage or 0) + 1
    use.extra_data = use.extra_data or {}
    use.extra_data.ChangeDamageType = fk.IceDamage
    use.extra_data.lb__juefa = player.id
    room:useCard(use)
    if player:isAlive() then
      player:drawCards(2, skel.name)
      local turn = room.logic:getCurrentEvent():findParent(GameEvent.Turn, true)
      if turn then
        turn:addCleaner(function()
          if player:isAlive() then
            local current = player.phase
            player.phase = Player.PhaseNone
            room:broadcastProperty(player, "phase")
            local phase = { ---@type PhaseDataSpec
              who = player,
              reason = skel.name,
              phase = Player.Play,
            }
            GameEvent.Phase:create(PhaseData:new(phase)):exec()
            player.phase = current
            room:broadcastProperty(player, "phase")
          end
        end)
      end
    end
  end,
})

skel:addEffect(fk.TargetSpecified, {
  can_refresh = function(self, event, target, player, data)
    return (data.extra_data or {}).lb__juefa == player.id and not data.to.dead
  end,
  on_refresh = function(self, event, target, player, data)
    data.to:addQinggangTag(data)
  end,
})


skel:addAcquireEffect(function(self, player, is_start)
  player.room:addSkill("#CenterArea")
end)

return skel
